package code;
import models.TreeNode;
public class HasSubtree {
    public boolean Bengio(TreeNode root1, TreeNode root2){
        if(root2 == null){
            return true;
        }
        if(root1 == null){
            return false;
        }
        if(root1.val != root2.val){
            return false;
        }
        return Bengio(root1.left,root2.left) && Bengio(root1.right,root2.right);
    }

    public boolean Solution(TreeNode root1,TreeNode root2){
        if(root1 == null || root2 == null){
            return false;
        }
        return Bengio(root1,root2) || Solution(root1.right,root2) || Solution(root1.left,root2);
    }
}
